package com.wanli.agent.homepage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wanli.agent.R;
import com.wanli.agent.bean.BranchBrankListBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 服务商列表
 */
public class ChooseBranchListAdapter extends RecyclerView.Adapter<ChooseBranchListAdapter.ViewHolder> {


    private List<BranchBrankListBean.DataBean.RecordBean> listsBeans;
    private Context context;
    private OnCallBackListener onCallBackListener;
    private int type;

    public ChooseBranchListAdapter(List<BranchBrankListBean.DataBean.RecordBean> listsBeans) {
        this.listsBeans = listsBeans;
        this.type = type;
    }

    public void setOnCallBackListener(OnCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_choose_bank, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        BranchBrankListBean.DataBean.RecordBean dataBean = listsBeans.get(position);
        holder.tvName.setText(dataBean.getLName());
        holder.itemView.setOnClickListener(v -> {
            onCallBackListener.onCallBack(dataBean.getLName(), dataBean.getBankCode());
        });
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_name)
        TextView tvName;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnCallBackListener {
        void onCallBack(String name, String code);
    }
}
